#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=1e6+10;
char s[N];
int a[N];
int b[N];
int c[N];
int d[N];
int e[N];
unordered_map <char,int> mp;
int main()
{
	int t;
	cin>>t;
	mp['A']=1;
	mp['B']=10;
	mp['C']=100;
	mp['D']=1000;
	mp['E']=10000;
	while(t--)
	{
		int n;
		scanf("%s",s+1);
	    int len=strlen(s+1);
	    
		ll ans=mp[s[len]];
		char mc=s[len];
		for(int i=len-1;i>0;i--)
		{
			if(s[i]<mc)
			{
				ans-=mp[s[i]];
			 }
			 else
			 {
			 	ans+=mp[s[i]];
			 	mc=s[i];
			 }
		}
		for()
		ll sum=ans;
		for(int i=1;i<=len;i++)
		{
			sum-=
		}
	}

	return 0;
}

